# include <bits/stdc++.h>
using namespace std;

struct list_node{
    int val;
    struct list_node * next;
};

list_node * input_list(void)
{
    int n, val;
    list_node * phead = new list_node();
    list_node * cur_pnode = phead;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &val);
        if (i == 1) {
            cur_pnode->val = val;
            cur_pnode->next = NULL;
        }
        else {
            list_node * new_pnode = new list_node();
            new_pnode->val = val;
            new_pnode->next = NULL;
            cur_pnode->next = new_pnode;
            cur_pnode = new_pnode;
        }
    }
    return phead;
}


list_node * reverse_list(list_node * head, int L, int R)
{
    // 1. 计算出单链表长度len, 判断其是否满足 1<=L<=R<=len;
    int len = 0;
    // 找到L-1的节点 prev,(反转部分的第一个节点);和R+1的节点 back(反转部分的后一个节点)
    list_node* cur = head;
    list_node* prev = nullptr, *back = nullptr;
    while(cur != nullptr){
        ++len;
       if(len == L-1)
            prev = cur;
        if(len == R+1)
            back = cur;
        cur = cur->next;
    }
    if(L > R || L < 1 || R > len)
        return head;
    // 如果prev为空说明L为head，要改变头节点，要返回新的头节点
    // 反转
    cur = (prev == nullptr) ?  head : prev->next;   
    list_node* node = cur->next;
    cur->next = back;   // 
    list_node* next = nullptr;
    while(node != back){  // 先反转，在连接
        next = node->next;
        node->next = cur;  // 反转一个节点
        cur = node;    
        node = next;
    }
    
    if(prev != NULL){
        prev->next = cur;
        return head;
    }
    return cur;
}

void print_list(list_node * head)
{
    while (head != NULL) {
        printf("%d ", head->val);
        head = head->next;
    }
    puts("");
}


int main ()
{
    int L, R;
    list_node * head = input_list();
    scanf("%d%d", &L, &R);
    list_node * new_head = reverse_list(head, L, R);
    print_list(new_head);
    return 0;
}